package com.self.serviceedu.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.self.commonutils.R;
import com.self.serviceedu.entity.EduCourse;
import com.self.serviceedu.entity.EduTeacher;
import com.self.serviceedu.service.EduCourseService;
import com.self.serviceedu.service.EduTeacherService;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/eduservice/teacherfront")
@CrossOrigin
public class TeacherFrontController {

    @Autowired
    private EduTeacherService teacherService;

    @Autowired
    private EduCourseService courseService;

    //1. 分页查询讲师
    @PostMapping("getTeacherFrontList/{page}/{limit}")
    public R getTeacherFrontList(
            @PathVariable("page") long page,
            @PathVariable("limit") long limit){

        Page<EduTeacher> teacherPage = new Page<>(page,limit);
        Map<String,Object> map = teacherService.getTeacherFrontList(teacherPage);

        //返回分页中的所有数据

        return R.ok().data(map);
    }

    //讲师详情
    @GetMapping("getTeacherInfoFrontById/{teacherId}")
    public R getTeacherInfoFrontById(
            @PathVariable("teacherId") String teacherId){


        //根据讲师ID查询讲师基本信息
        EduTeacher teacher = teacherService.getById(teacherId);

        //根据讲师Id查询所讲课程
        QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();
        wrapper.eq("teacher_id",teacherId);
        List<EduCourse> list = courseService.list(wrapper);

        return R.ok().data("teacherInfo",teacher).data("courseList",list);
    }

}
